package com.mulan.estatemanagement.controller;

import com.github.pagehelper.Page;
import com.mulan.estatemanagement.common.MessageConstant;
import com.mulan.estatemanagement.common.PageResult;
import com.mulan.estatemanagement.common.Result;
import com.mulan.estatemanagement.common.StatusCode;
import com.mulan.estatemanagement.domain.Building;
import com.mulan.estatemanagement.service.BuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @Auth: xieqihang
 * @Desc: 楼栋管理控制层:只负责接受浏览器发送来的请求和请求参数，调用service层获取业务逻辑加工处理后的数据
 */
@RestController
@RequestMapping("/building")
public class BuildingController {
    @Autowired
    private BuildingService buildingServiceImpl;

    @RequestMapping("/find")
    public Result find(){
        List<Building> all = buildingServiceImpl.findAll();
        return new Result(false,200,"请求成功",all);
    }

    @RequestMapping("/search")
    public PageResult search(@RequestBody Map searchMap){
        Page<Building> page = buildingServiceImpl.search(searchMap);
        return new PageResult(true, StatusCode.OK, MessageConstant.COMMUNITY_SEARCH_SUCCESS,page.getResult(),page.getTotal());
    }
    @RequestMapping("/add")
    public Result add(@RequestBody Building building){
        Boolean add = buildingServiceImpl.add(building);
        return new Result(true, StatusCode.OK, MessageConstant.COMMUNITY_ADD_SUCCESS);
    }
    @RequestMapping("/findById")
    public Result findById(Integer id){
        Building building = buildingServiceImpl.findById(id);
        return new Result(true, StatusCode.OK, MessageConstant.COMMUNITY_FIND_BY_ID_SUCCESS,building);
    }
    @RequestMapping("/update")
    public Result update(@RequestBody Building building){
        Boolean update = buildingServiceImpl.update(building);
        return new Result(true, StatusCode.OK, MessageConstant.COMMUNITY_UPDATE_SUCCESS);
    }
    @RequestMapping("/del")
    public Result del(@RequestBody List<Integer> ids){
        Boolean del = buildingServiceImpl.del(ids);
        return new Result(true, StatusCode.OK, MessageConstant.COMMUNITY_DELETE_SUCCESS,ids);
    }

}

